﻿<phone:PhoneApplicationPage
    x:Class="ChinaUnicom.Views.Home"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:local="clr-namespace:ChinaUnicom.Controls"
    xmlns:src="clr-namespace:ChinaUnicom.Converters"
    xmlns:avatar="clr-namespace:Avatar.Controls;assembly=avatar.wp"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False"
    toolkit:TiltEffect.IsTiltEnabled="True"
    Name="this">

    <!--Transitions-->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:SlideTransition Mode="SlideLeftFadeIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:SlideTransition Mode="SlideLeftFadeIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:SlideTransition Mode="SlideLeftFadeOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:SlideTransition Mode="SlideLeftFadeOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="LogoIconStyle" TargetType="Image">
            <Setter Property="Source" Value="/Themes/Images/logo.png"/>
            <Setter Property="Grid.Row" Value="0"/>
            <Setter Property="Height" Value="86"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
        </Style>
        <Style x:Key="ClientIconStyle" TargetType="Image">
            <Setter Property="Source" Value="/Themes/Images/user.png"/>
            <Setter Property="Grid.Column" Value="0"/>
            <Setter Property="Height" Value="35"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
        <Style x:Key="ClientNameStyle" TargetType="TextBlock">
            <Setter Property="Grid.Column" Value="1"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Foreground" Value="White"/>
        </Style>
        <Style x:Key="MobileIconStyle" TargetType="Image">
            <Setter Property="Source" Value="/Themes/Images/phone.png"/>
            <Setter Property="Grid.Column" Value="2"/>
            <Setter Property="Height" Value="35"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
        <Style x:Key="MobileTextStyle" TargetType="TextBlock">
            <Setter Property="Grid.Column" Value="3"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Foreground" Value="White"/>
        </Style>
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">

        <Grid.Resources>
            <Style x:Key="ProgressBarStyle" TargetType="ProgressBar">
                <Setter Property="Grid.Row" Value="0"/>
                <Setter Property="VerticalAlignment" Value="Top"/>
                <Setter Property="Foreground" Value="White"/>
            </Style>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Background="#FF9F0802">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="40"/>
                </Grid.RowDefinitions>
                <Image Style="{StaticResource LogoIconStyle}"/>
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="45"/>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition Width="35"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="100"/>
                    </Grid.ColumnDefinitions>
                    <Image Style="{StaticResource ClientIconStyle}"/>
                    <TextBlock Style="{StaticResource ClientNameStyle}"
                               Text="{Binding Client}"/>

                    <Image Style="{StaticResource MobileIconStyle}" Visibility="{Binding MobileVisibility}"/>
                    <TextBlock Style="{StaticResource MobileTextStyle}" Text="{Binding Mobile}" Visibility="{Binding MobileVisibility}"/>

                    <Image Grid.Column="4" Source="/Themes/Images/offline.png" Visibility="{Binding OfflineVisibility}"/>
                </Grid>
            </Grid>
        </Border>

        <controls:Pivot Grid.Row="1" x:Name="PivotControl">

            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="套餐余量" FontSize="62"/>
                </controls:PivotItem.Header>
                <avatar:PullList ItemsSource="{Binding Package.Items}" 
                                 Visibility="{Binding PackageContentVisibility}"
                                 Pulled="OnPackagePulled"
                                 Released="OnPackageReleased">
                    <avatar:PullList.PullPanel>
                        <StackPanel>
                            <TextBlock Text="{Binding PackagePullrefresh}" Style="{StaticResource PulledTextStyle}"/>
                        </StackPanel>
                    </avatar:PullList.PullPanel>
                    <avatar:PullList.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="12, 10, 12, 10">
                                <TextBlock Text="{Binding Name}" FontSize="30"/>
                                <TextBlock Text="{Binding Value}" Foreground="{StaticResource PhoneAccentBrush}"/>
                                <TextBlock Foreground="{StaticResource PhoneSubtleBrush}">
                                                <Run Text="{Binding Details[0].Name}"/>
                                                <Run Text=" : "/>
                                                <Run Text="{Binding Details[0].Value}"/>
                                </TextBlock>
                                <TextBlock Foreground="{StaticResource PhoneSubtleBrush}">
                                                <Run Text="{Binding Details[1].Name}"/>
                                                <Run Text=" : "/>
                                                <Run Text="{Binding Details[1].Value}"/>
                                </TextBlock>
                                <TextBlock Foreground="{StaticResource PhoneSubtleBrush}">
                                                <Run Text="{Binding Details[2].Name}"/>
                                                <Run Text=" : "/>
                                                <Run Text="{Binding Details[2].Value}"/>
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </avatar:PullList.ItemTemplate>
                </avatar:PullList>
            </controls:PivotItem>

            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="当月话费" FontSize="62"/>
                </controls:PivotItem.Header>
                <avatar:PullList ItemsSource="{Binding Fee.Items}" 
                                 Visibility="{Binding FeeContentVisibility}"
                                 Pulled="OnFeePulled"
                                 Released="OnFeeReleased"
                                 ItemTemplate="{StaticResource BasicTextTemplate}"
                                 Margin="12, 0, 12, 40">
                    <avatar:PullList.PullPanel>
                        <StackPanel>
                            <TextBlock Text="{Binding FeePullrefresh}" Style="{StaticResource PulledTextStyle}"/>
                        </StackPanel>
                    </avatar:PullList.PullPanel>
                </avatar:PullList>
            </controls:PivotItem>

            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="历史账单" FontSize="62"/>
                </controls:PivotItem.Header>
                <ScrollViewer>
                    <StackPanel Visibility="{Binding FeeContentVisibility}" 
                                Margin="0,0,0,40">
                        <ItemsControl Margin="12 0" ItemsSource="{Binding FeeHistories}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Button Margin="0 10" 
                                                Grid.Column="1" 
                                                Template="{StaticResource SampleButtonTemplate}"
                                                Command="{Binding ElementName=this, Path=DataContext.ListFeeHistoryCommand}"
                                                CommandParameter="{Binding Occurred}">
                                        <Button.Content>
                                            <StackPanel>
                                                <TextBlock Text="{Binding Occurred, Converter={StaticResource dateConverter},ConverterParameter=YYYYMM}" 
                                                       FontSize="30"/>
                                                <TextBlock Foreground="{StaticResource PhoneAccentBrush}" FontSize="20">
                                                    <Run Text="消费合计 : "/>
                                                    <Run Text="{Binding Fee}"/>
                                                </TextBlock>
                                            </StackPanel>
                                        </Button.Content>
                                    </Button>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                        <Button Template="{StaticResource MoreItemIconButton}" 
                                Margin="12 24"
                                Visibility="{Binding FeeHistories.HasMore, Converter={StaticResource booleanVisibilityConverter}}"
                                Command="{Binding ElementName=this, Path=DataContext.MoreFeeHistoriesCommand}">
                            <Button.Content>
                                <TextBlock Text="更多历史账单" 
                                           FontSize="32" 
                                           VerticalAlignment="Center"/>
                            </Button.Content>
                        </Button>
                    </StackPanel>
                </ScrollViewer>
            </controls:PivotItem>

        </controls:Pivot>

        <ProgressBar IsEnabled="{Binding PackageProgressEnabled}" 
                     IsIndeterminate="{Binding PackageProgressEnabled}" 
                     Visibility="{Binding PackageProgressVisibility}" 
                     Style="{StaticResource ProgressBarStyle}"/>

        <ProgressBar IsEnabled="{Binding FeeProgressEnabled}" 
                     IsIndeterminate="{Binding FeeProgressEnabled}" 
                     Visibility="{Binding FeeProgressVisibility}"  
                     Style="{StaticResource ProgressBarStyle}"/>

        <ProgressBar IsEnabled="{Binding FeeHistoryProgressEnabled}" 
                     IsIndeterminate="{Binding FeeHistoryProgressEnabled}" 
                     Visibility="{Binding FeeHistoryProgressVisibility}" 
                     Style="{StaticResource ProgressBarStyle}"/>

    </Grid>
    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>